package com.bstek.demo.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.bstek.demo.entity.User;
import com.bstek.demo.service.UserService;
import com.bstek.dorado.annotation.Expose;
import com.bstek.dorado.web.DoradoContext;
/**
 * 登陆登出控制层
 * @author lemon
 *
 */
@Component
public class LogController {

	@Autowired UserService userService;
	
	/**
	 * 登陆检测方法
	 * @author lemon
	 * @param param 用户信息
	 * @return 返回检测结果
	 */
	@Expose
	public Map doLogin(Map param){
		String username = (String)param.get("username");
		String password = (String)param.get("password");
		User user = new User();
		
		user.setUsername(username);
		user.setPassword(password);
		
		
		Map result = new HashMap();
		if(userService.isValue(user)){
			result.put("url","com.bstek.demo.view.Main.d");
			result.put("result",true);
		}else{
			String message = "�û��������벻ƥ�䣡";
			result.put("errormsg",message);
			result.put("result",false);
			
		}
		return result;
	}
	/**
	 * 登出
	 * @author lemon
	 * @return 返回登出结果
	 */
	@Expose
	public Map doLogout(){
		
		DoradoContext ctx = DoradoContext.getCurrent();
		HttpServletRequest request = ctx.getRequest();
		request.setAttribute("user", null);
		Map map = new HashMap();
		map.put("url", "cn.bstek.demo.view.Login.d");
		map.put("result", true);
		return map;
	}
}
